package com.rxt.interceptor;

import com.rxt.common.exception.CustomException;
import com.rxt.common.result.ResultCodeEnum;
import com.rxt.util.BankThreadLocal;
import com.rxt.util.BaseContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpMethod;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Slf4j
public class BankUserLoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        log.info("TokenHandlerInterceptor - url: {}, method: {}", request.getRequestURI(), request.getMethod());
        if (HttpMethod.OPTIONS.toString().equals(request.getMethod())) {
            return true;
        }
        if (BankThreadLocal.get() == null) {
            throw new CustomException(ResultCodeEnum.PERMISSION);
        }
        return true;
    }
}
